<?php
   include("./dbconn.php");

   $search = $_GET["search"];

   if (strlen($search) == 0){
      $sql = "select * from midata  order by Id desc";
   }else{
      $sql = "select * from midata where title='$search' order by Id desc";
   }

   $result = $conn->query($sql);
  
   if ($result->num_rows > 0){
    //  $list = [{},{},{}]
     for ($i = 0; $i < $result->num_rows; $i++){
        $list[] = mysqli_fetch_assoc($result);
     }
     $data["code"] = 0;
     $data["list"] = $list;
   }else{
     $data["code"] = 1;
   }
   echo json_encode($data);

?>